package com.edu.exam.entity.examination.paper;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;
import com.edu.exam.enums.ResourceType;
import com.edu.exam.enums.ReservationStatus;

/**
 * 资源预留实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：resource_reservation
 *
 * <p>考试资源预留记录，存储场地、设备等资源的预留信息。
 * 用于考试资源的统一管理和调度，确保考试所需的各类资源能够得到合理分配和使用。</p>
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
public class ResourceReservation {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "plan_item_id", nullable = false)
    private Long planItemId;

    @Column(name = "resource_type", length = 50, nullable = false)
    private String resourceType;

    @Column(name = "resource_id", length = 50, nullable = false)
    private String resourceId;

    @Column(name = "resource_name", length = 200)
    private String resourceName;

    @Column(name = "start_time", nullable = false)
    private LocalDateTime startTime;

    @Column(name = "end_time", nullable = false)
    private LocalDateTime endTime;

    @Column(name = "reservation_status", length = 50, nullable = false)
    private String reservationStatus;

    @Column(name = "priority", nullable = false)
    private Integer priority = 5; // 预留优先级，1-10，数字越小优先级越高

    @Column(name = "capacity")
    private Integer capacity; // 资源容量（如场地座位数）

    @Column(name = "allocated_quantity")
    private Integer allocatedQuantity; // 已分配数量

    @Column(name = "confirmation_code", length = 50)
    private String confirmationCode; // 确认码

    @Column(name = "notes", length = 500)
    private String notes; // 备注信息

    @Column(name = "confirmed_by", length = 64)
    private String confirmedBy; // 确认人

    @Column(name = "confirmed_time")
    private LocalDateTime confirmedTime; // 确认时间

    @Column(name = "cancelled_by", length = 64)
    private String cancelledBy; // 取消人

    @Column(name = "cancelled_time")
    private LocalDateTime cancelledTime; // 取消时间

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    // 关联实体
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "plan_item_id", insertable = false, updatable = false)
    private PlanItem planItem;

}